
/**
 * Copyright 2013 Green global company. All rights reserved. Use is subject to license terms.
 */
package webdev.danagtravel;

import webdev.customlib.slidingmenu.BaseActivity;
import webdev.customlib.slidingmenu.SlidingMenu;
import webdev.fragment.ChangePasswordFragment;
import webdev.fragment.InforOverViewFragment;
import webdev.fragment.LeftNavigationFragment;
import webdev.fragment.ListAmThucFragment;
import webdev.fragment.MapPlacesFragment;
import webdev.fragment.PhotosFragment;
import webdev.fragment.UserProfileFragment;
import webdev.fragment.VideosFragment;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import dev.danang.R;

public class MainActivity extends BaseActivity implements OnClickListener
 {
	
    public FragmentManager fragmentManager;

    // Image view
    private ImageView mImgOpenLeftNavigation;
    private ImageView mImgOpenSearchNavigation;
		


    // Text view

    // Fragment
    public UserProfileFragment userProfileFragment;
    public InforOverViewFragment inforOverViewFragment;
    public PhotosFragment albumAndPhotoFragment;
    public VideosFragment videosFragmentNew;
    public ChangePasswordFragment changePasswordFragment;
    
    public MapPlacesFragment mapFragment;
    public ListAmThucFragment listFragment;
	
	private Toast toastExit;
	TextView  tv_header;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        setValue();
        setEvent();

        // Load dash board first
        inforOverViewFragment = InforOverViewFragment.newInstance(InforOverViewFragment.SHOW_OVERVIEW);
        setFragmentContent(inforOverViewFragment, InforOverViewFragment.TAG);
    }

    /**
     * This method is used to set fragment content
     * @param fragment
     * @param tag
     */
    public void setFragmentContent(Fragment fragment, String tag) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame_main, fragment, tag);
        fragmentTransaction.commit();
        slidingMenu.showContent();
    }

    @SuppressLint("ShowToast")
	@Override
    public void init() {
    	toastExit = Toast.makeText(this, R.string.message_quit_app, Toast.LENGTH_SHORT);
        fragmentManager = getSupportFragmentManager();
        // Image view
        mImgOpenLeftNavigation = (ImageView) findViewById(R.id.img_menu);
        mImgOpenSearchNavigation = (ImageView) findViewById(R.id.img_menu_search);
        // Text view
        tv_header = (TextView)findViewById(R.id.tv_header);
        
    }
    public void setHeader(String header)
    {
    	tv_header.setText(header);
    }


    @Override
    public void setValue() {
    	setHeader("TỔNG QUAN");
    }

    @Override
    public void setEvent() {
        // Image view
        mImgOpenLeftNavigation.setOnClickListener(this);
        mImgOpenSearchNavigation.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.img_menu:
            slidingMenu.setMode(SlidingMenu.LEFT);
            toggle();
            break;
        case R.id.img_menu_search:
            slidingMenu.setMode(SlidingMenu.RIGHT);
            toggle();
            break;
        default:
            break;
        }
        slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
    }
    @Override
    public void onBackPressed() {
       if (mLeftNavigationFragment.curentTab != LeftNavigationFragment.TAB_INFOR_OVERVIEW) {
        	mLeftNavigationFragment.showFocus(LeftNavigationFragment.TAB_INFOR_OVERVIEW);
        	setFragmentContent(InforOverViewFragment.newInstance(InforOverViewFragment.SHOW_OVERVIEW), InforOverViewFragment.TAG);
        } else {
        	if (fragmentManager.getBackStackEntryCount() > 1) {
				fragmentManager.popBackStack();
			} else {
				if (toastExit.getView().isShown()) {
					finish();
				} else {
					toastExit.show();
				}
			}
        }
    }
}
